import { setCategories, getCategories } from '@/utils/auth'
import { categories } from '@/api/category'
const state = {
  categories: getCategories()
}

const mutations = {
  'SET_CATEGORY' (state, data) {
    setCategories(data)
    state.categories = data
  }
}

const actions = {
  async fetchCategory ({ commit }) {
    const res = await categories()
    if (res.data && res.data.length) {
      commit('SET_CATEGORY', res.data)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
